#define _CRT_SECURE_NO_WARNINGS 1

#include <string>
using namespace std;

class Solution {
public:
    string countAndSay(int n) {
        string ret = "1";
        while (--n)
        {
            string tmp;
            int len = ret.size();
            for (int left = 0, right = 0; right <= len; ++right)
            {
                if (ret[left] != ret[right])
                {
                    tmp += to_string(right - left) + ret[left];
                    left = right;
                }
            }
            ret = tmp;
        }
        return ret;
    }
};